<?php

namespace backend\modules\supplier\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use backend\modules\supplier\models\PurchaseInDetail;

/**
 * PurchaseInDetailSearch represents the model behind the search form about `backend\modules\supplier\models\PurchaseInDetail`.
 */
class PurchaseInDetailSearch extends PurchaseInDetail
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id', 'product_id', 'product_sn', 'number'], 'integer'],
            [['master_id', 'goods_name', 'goods_attr', 'unit', 'remark'], 'safe'],
            [['price'], 'number'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        
        $query = PurchaseInDetail::find();

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        if (!($this->load($params) && $this->validate())) {
            return $dataProvider;
        }

        $query->andFilterWhere([
            'id' => $this->id,
            'product_id' => $this->product_id,
            'product_sn' => $this->product_sn,
            'number' => $this->number,
            'price' => $this->price,
        ]);

        $query->andFilterWhere(['like', 'master_id', $this->master_id])
            ->andFilterWhere(['like', 'goods_name', $this->goods_name])
            ->andFilterWhere(['like', 'goods_attr', $this->goods_attr])
            ->andFilterWhere(['like', 'unit', $this->unit])
            ->andFilterWhere(['like', 'remark', $this->remark]);

        return $dataProvider;
    }
}
